package school.xauat;

import org.junit.jupiter.api.Test;

import java.util.Arrays;

/**
 * @author ：zsy
 * @date ：Created 2021/6/18 9:23
 * @description：
 */
public class Main {

    @Test
    public void Test() {
        Solution solution = new Solution();
        System.out.println(solution.canJump(new int[]{4,2,0,0,1,1,4,4,4,0,4,0}));

    }

    class Solution {
        public boolean canJump(int[] nums) {
            int n = nums.length;
            int rightmost = 0;
            for (int i = 0; i < n; i++) {
                if (i <= rightmost) {
                    rightmost = Math.max(rightmost, nums[i] + i);
                }
                if (rightmost > n - 1) return true;
            }
            return false;
        }
    }
}
